package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.Doctor;
import com.woniuxy.entity.InHospital;
import com.woniuxy.entity.Nurse;
import com.woniuxy.entity.SickBed;
import com.woniuxy.entity.dto.NursePatientDTO;
import com.woniuxy.mapper.DoctorMapper;
import com.woniuxy.mapper.InHospitalMapper;
import com.woniuxy.mapper.NurseMapper;
import com.woniuxy.mapper.SickBedMapper;
import com.woniuxy.service.NursePatientService;
import com.woniuxy.service.SaasService;
import com.woniuxy.util.GetUserContent;
import com.woniuxy.util.PageParam;
import com.woniuxy.util.ResponseData;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NursePatientServiceImpl implements NursePatientService, SaasService {
    @Autowired
    DoctorMapper doctorMapper;

    @Autowired
    SickBedMapper sickBedMapper;
    @Autowired
    NurseMapper nurseMapper;
    @Autowired
    InHospitalMapper inHospitalMapper;

    @Override
    @SneakyThrows
    public ResponseData<?> querySelect() {
        Long userId = (Long) GetUserContent.getUserInfo().get("userId");
        Nurse nurse = nurseMapper.queryNurse(Math.toIntExact(userId));
        Integer nurDeId = nurse.getNurDeId();
        List<Doctor> doctors = doctorMapper.queryListByDeId(nurDeId);
        List<SickBed> sickBeds = sickBedMapper.queryListByDeId(nurDeId);
        Map map = new HashMap();
        map.put("doctors",doctors);
        map.put("sickBeds",sickBeds);
        return new ResponseData<>().ok(map);

    }

    @Override
    @SneakyThrows
    public ResponseData<?> queryHzList(PageParam<NursePatientDTO> pageParam) {
        Long userId = (Long) GetUserContent.getUserInfo().get("userId");
        Nurse nurse = nurseMapper.queryNurse(Math.toIntExact(userId));
        Integer nurDeId = nurse.getNurDeId();
        PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
        pageParam.getParam().setDeId(nurDeId);
        List<InHospital> inHospitals = inHospitalMapper.queryHzList(pageParam.getParam());
        PageInfo pageInfo = new PageInfo(inHospitals);
        return new ResponseData<>().ok(pageInfo);
    }
}
